<template>
	<view>
		<view class="cu-bar bg-gradual-blue">
			<view class="action">
				<text class="cuIcon-back" @tap="back"></text> 返回
			</view>
			<view class="content text-bold">
				添加rss订阅
			</view>
		</view>
		<view class="cu-item shadow" style="margin-top: 20rpx;">
			<view class="cu-form-group">
				<view class="title">订阅名称</view>
				<input placeholder="输入订阅名称" name="input" @input="inputName"></input>
				<text class='cuIcon-addressbook text-orange'></text>
			</view>

			<view class="cu-form-group">
				<view class="title">订阅地址</view>
				<input placeholder="输入订阅地址" name="input" @input="inputAddress"></input>
				<text class='cuIcon-global text-orange'></text>
			</view>
			<button class="bg-blue" style="margin-top: 20rpx;" @tap="sumit"> 提交订阅</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				addrss: ''
			}
		},
		methods: {
			inputName(e) {
				this.name = e.detail.value
			},
			inputAddress(e) {
				this.addrss = e.detail.value
			},back(){
				uni.navigateBack()
			},
			sumit() {
				if (this.name && this.addrss) {

					var item = {
						'name': this.name,
						'url': this.addrss
					}
					this.$api.getRssHub(this.addrss).then((res) => {
						
							// 地址有效
							var items =uni.getStorageSync('rssAddrss');
							
							 if(items){
								 var value = JSON.parse(items)
								 value.push(item)
								  uni.setStorageSync('rssAddrss',JSON.stringify(value))
							 }else{
								 items =[]
								 items.push(item)
								 uni.setStorageSync('rssAddrss',JSON.stringify(items))
							 }
							 uni.showToast({
							 	'title': '添加订阅成功',
							 })
							uni.$emit('load',true)
						
					}).catch((e) => {
						uni.showToast({
							'title': '无效的地址'
						})
					})
				} else {
					uni.showToast({
						'title': '名称和地址不能为空'
					})
				}
			}
		}
	}
</script>

<style>

</style>
